/**
 * 
 */
package com.sicocre.business.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;
import com.sicocre.beans.Pagos;
import com.sicocre.business.dao.IPagoDao;

/**
 * @author lserrano
 *
 */

@Repository
public class PagoDaoImpl implements IPagoDao {

	private static final Logger log = Logger.getLogger(PagoDaoImpl.class);

	private JdbcTemplate jdbcTemplate;

	public static final String INSERT_PAGOS = "INSERT INTO sicocre.pago(monto_pago, fch_pago,tdc, num_tdc,cheque,num_cheque,id_banco,efectivo, id_apertura)VALUES (?,?,?,?,?,?,?,?,?)";    
	
	
	
	@Autowired
	public void setDataSource(DataSource ds){
		jdbcTemplate=new JdbcTemplate(ds);
	}


		
	
	public int insertarPago(Pagos pago, int idApertura){
		 
		
		
		int tdc =0;
		int cheque=0;
		int efectivo =0;

		if (pago.isTdc()){
			tdc = 1;
			log.info("EL valor de TDC es tru...");
		}
		if (pago.isCheque()){
			cheque=1;
		}
		if(pago.isEfectivo()){
			efectivo=1;
		}

		
		int insertaPago = jdbcTemplate.update(INSERT_PAGOS,new Object[]{pago.getMonto(), pago.getFchPago(), tdc, pago.getNumTdc(),
				cheque, pago.getNumCheque(), pago.getBanco().getIdBanco(), efectivo, idApertura });
	
		return insertaPago;
	}


	

	
}
